<template>
  <div class="app-container mod-hot-search">
    <!-- 搜索相关区域 -->
    <div class="filter-container">
      <el-form :inline="true" :model="pageQuery" class="demo-form-inline">
        <el-form-item label="关键字">
          <el-input
            v-model="pageQuery.title"
            size="mini"
            placeholder="请输入集合编号"
          />
        </el-form-item>
        <el-form-item label="订单来源">
          <el-select
            v-model="pageQuery.from"
            size="mini"
            placeholder="请选择订单来源"
            clearable
          >
            <el-option label="全部" value="0" />
            <el-option label="APP" value="1" />
            <el-option label="小程序" value="2" />
            <el-option label="吧台直售" value="3" />
          </el-select>
        </el-form-item>
        <el-form-item label="交易时间">
          <el-date-picker
            v-model="pageQuery.time"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>

        <el-form-item label="区域位置">
          <el-select
            v-model="pageQuery.status"
            size="mini"
            placeholder="请选择区域位置"
            clearable
          >
            <el-option label="全部" value="0" />
            <el-option label="河北省邯郸-丛台区" value="1" />
            <el-option label="河北省邯郸-邯山区" value="2" />
            <el-option label="河北省邯郸-复兴区" value="3" />
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button
            type="primary"
            size="mini"
            icon="el-icon-search"
            @click="getPage()"
            >查询</el-button
          >
          <el-button
            size="mini"
            icon="el-icon-delete"
            @click="clearSearchInfo()"
            >清空</el-button
          >
        </el-form-item>
      </el-form>
    </div>

    <!-- 列表相关区域 -->
    <el-table
      v-loading="pageLoading"
      :data="pageVO.list"
      border
      fit
      highlight-current-row
      style="width: 100%"
    >
      <!-- 订单编号 -->
      <el-table-column
        label="订单编号"
        prop="orderId"
        align="center"
      >
        <template slot-scope="{ row }">
          <span>{{ row.orderId }}</span>
        </template>
      </el-table-column>
      <!-- 吧台编号 -->
      <el-table-column
        label="吧台编号"
        prop="number"
        align="center"
      >
        <template slot-scope="{ row }">
          <span>{{ row.number }}</span>
        </template>
      </el-table-column>
      <!-- 所属商品 -->
      <el-table-column
        label="所属商品"
        prop="spuName"
        align="center"
      >
        <template slot-scope="{ row }">
          <span>{{ row.spuName }}</span>
        </template>
      </el-table-column>
      <!-- 订单数量 -->
      <el-table-column
        label="订单数量"
        prop="count"
        align="center"
      >
        <template slot-scope="{ row }">
          <span>{{ row.count }}</span>
        </template>
      </el-table-column>
      <!-- 总金额 -->
      <el-table-column
        label="总金额"
        prop="spuTotalAmount"
        align="center"
      >
        <template slot-scope="{ row }">
          <span>{{ row.spuTotalAmount }}</span>
        </template>
      </el-table-column>
      <!-- 实际支付金额 -->
      <el-table-column
        label="实际支付金额"
        prop="spuTotalAmount"
        align="center"
      >
        <template slot-scope="{ row }">
          <span>{{ row.spuTotalAmount }}</span>
        </template>
      </el-table-column>
      <!-- 订单来源 -->
      <el-table-column
        label="订单来源"
        prop="orderSource"
        align="center"
      >
        <template slot-scope="{ row }">
          <span v-if="row.orderSource == 1">APP -酒速达</span>
          <span v-if="row.orderSource == 2">APP-自取</span>
          <span v-if="row.orderSource == 3">小程序-酒速达</span>
          <span v-if="row.orderSource == 4">小程序-自取</span>
          <span v-if="row.orderSource == 5">吧台直售</span>
        </template>
      </el-table-column>
      <!-- 创建时间 -->
      <el-table-column
        label="创建时间"
        prop="createTime"
        align="center"
      >
        <template slot-scope="{ row }">
          <span>{{ row.createTime }}</span>
        </template>
      </el-table-column>
      <!-- 订单状态 -->
      <el-table-column
        label="订单状态"
        prop="status"
        align="center"
      >
        <template slot-scope="{ row }">
          <span>{{ row.status == 1 ? '待付款' : row.status == 2 ? '待发货' : row.status == 3 ? '待收货(已发货)' : row.status == 5 ? '成功' : '失败' }}</span>
        </template>
      </el-table-column>

      <el-table-column
        :label="$t('table.actions')"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="{ row }">
          <el-button
            type="primary"
            size="mini"
            @click="goDetail(row)"
          >
            查看
          </el-button>
          
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页条 -->
    <pagination
      v-show="pageVO.total > 0"
      :total="pageVO.total"
      :page.sync="pageQuery.pageNum"
      :limit.sync="pageQuery.pageSize"
      @pagination="getPage()"
    />
  </div>
</template>

<script>
import permission from "@/directive/permission/index.js";
import Pagination from "@/components/Pagination";
import * as api from "@/api/order/index";
import * as api_shop from "@/api/platform/shop";

export default {
  name: "",
  components: { Pagination },
  directives: { permission },
  data() {
    return {
      // 查询的参数
      pageQuery: {
        pageSize: 10,
        pageNum: 1,
        title: null,
        content: null,
        status: null,
        shopId: null,
      },
      // 返回参数
      pageVO: {
        list: [], // 返回的列表
        total: 0, // 一共多少条数据
        pages: 0, // 一共多少页
      },
      // loading
      pageLoading: true,
    };
  },
  mounted() {
    this.getPage();
  },
  methods: {
    getPage() {
      this.pageLoading = true;
      api.getPage({ ...this.pageQuery }).then((pageVO) => {
        this.pageVO = pageVO;
        this.pageLoading = false;
      });
    },
    goDetail(row) {
      this.$router.push({
        path: `/barcounter/order/detail?detail=${JSON.stringify(row)}`
      })
    },
    
    clearSearchInfo() {
      // 若请求参数某项没值，则不传此参数
      this.pageQuery.pageNum = 1;
      this.pageQuery.pageSize = 10;
      this.pageQuery.title = null;
      this.pageQuery.content = null;
      this.pageQuery.status = null;
      this.pageQuery.shopId = null;
      this.getPage();
    },
  },
};
</script>

<style lang="scss" scoped>
.mod-hot-search {
  .el-form--inline {
    .el-form-item {
      margin-right: 20px;
    }
  }
}
</style>
